package com.ruoyi.config;


import com.ruoyi.interceptor.LoginInterceptor;
import com.ruoyi.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: lsx
 * @Description:
 * @Create:  2025/1/7 9:56
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TokenInterceptor())
                .addPathPatterns("/**");

        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/user/getInfo")
                .addPathPatterns("/user/updatePassword")
                .addPathPatterns("/user/checkPassword")
                .addPathPatterns("/user/updateUserInfo")
                .addPathPatterns("/user/changePhone")
                .addPathPatterns("/forum/publish")
                .addPathPatterns("/forum/like/**")
                .addPathPatterns("/forum/delete")
                .addPathPatterns("/watchlist/**")
                .addPathPatterns("/comment/likeComment")
                .addPathPatterns("/comment/deleteComment")
                .addPathPatterns("/comment/addComment");
    }

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        // 配置全局跨域
//        registry.addMapping("/**") // 对所有的请求开启跨域
//                .allowedOrigins("*") // 允许所有来源
//                .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的请求方法
//                .allowedHeaders("*") // 允许的请求头
//                .allowCredentials(true) // 允许发送凭证（如 Cookies）
//                .maxAge(3600); // 缓存预检请求的时间
//    }
}